﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMTC.Model.Model;
using SMTC.WebCommon.Common;
using SMTC.BO.BaseInfo;
using System.Web.UI.HtmlControls;
public partial class BaseInfoManagement_MounterInfoMaintain : BasePage
{
    ProductionUnitProccessServices _service = new ProductionUnitProccessServices();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            if (Request["action"] != null && Request["action"].ToString() == "select")
            {
                this.gvProductionUnitView.Columns[0].Visible = true;
                this.gvProductionUnitView.Columns[6].Visible = false;
                btnNew.Visible = false;
                btnOK.Visible = true;
                btnVendorContactCancel.Visible = true;
                title.Text = Resources.Resource.PleaseChooseMounter;//"请选择贴片机";
                ProductionUnitViewDataSource.SelectParameters.Add("sel", "1");

            }
            else
            {
                ProductionUnitViewDataSource.SelectParameters.Add("sel", "0");
            }
        }
    }

    protected void btn_SaveCopy_Click(object sender, EventArgs e)
    {
        if (_service.CopyPuVersion(dll_PUVersion.Text, this.txt_VersionRemark.Text) == true)
        {
            ShowMessage("Copy Version Success");
        }
        else
        {
            ShowMessage("Copy Version Fail");
        }
    }
    protected override void OnPreRender(EventArgs e)
    {
        if (Request["action"] != null && Request["action"].ToString() == "select")
        {
            HtmlGenericControl tagBase = new HtmlGenericControl("base");
            tagBase.Attributes.Add("target", "_self");
            this.Page.Header.Controls.Add(tagBase);
        }
        base.OnPreRender(e);
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        this.gvProductionUnitView.DataBind();
    }


    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (_service.InsertPU(GetPU()))
        {
            ShowMessage(Resources.Resource.MounterInfoAddSuccess);//"添加贴片机成功！"
        }
        else
        {
            ShowMessage(Resources.Resource.MounterInfoAddFailed);//"添加贴片机失败！"
        }
        this.gvProductionUnitView.DataBind();
    }
    protected void btnUpd_Click(object sender, EventArgs e)
    {
        if (_service.UpdatePU(GetPU()))
        {
            ShowMessage(Resources.Resource.MounterInfoUpdSuccess);//"维护贴片机成功！"
        }
        else
        {
            ShowMessage(Resources.Resource.MounterInfoUpdFailed);//"维护贴片机失败！"
        }
        this.gvProductionUnitView.DataBind();
    }

    protected void gvProductionUnitView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Del")
        {
            try
            {
                if (_service.DelPUByPUID(e.CommandArgument.ToString()))
                {
                    ShowMessage(Resources.Resource.MounterInfoDelSuccess);//"删除贴片机成功！"
                }
                else
                {
                    ShowMessage(Resources.Resource.MounterInfoDelFailed);//"删除贴片机失败！"
                }
                this.gvProductionUnitView.DataBind();

            }
            catch (Exception ex)
            {
              
            }
        }
    }
    private SMT_ProductionUnitModel GetPU()
    {
        
        SMT_ProductionUnitModel pu = new SMT_ProductionUnitModel();
        pu.PUID = hidMounterID.Value;
        pu.PUType = this.txtType2.Text;
        pu.PUCapacity = Convert.ToInt32(this.txtAbility2.Text);
        pu.Para = Convert.ToDouble(this.txtParameter2.Text);
        pu.ModifyPerson = this.UserName;
        pu.ModifyDateTime = DateTime.Now;
        pu.EffectiveTimeEnd = txtEffectiveTimeEnd2.Value; if (string.IsNullOrEmpty(pu.EffectiveTimeEnd)) pu.EffectiveTimeEnd = "2999-12-31";
        pu.EffectiveTimeStart = txtEffectiveTimeStart2.Value; if (string.IsNullOrEmpty(pu.EffectiveTimeStart)) pu.EffectiveTimeStart = "1900-1-1";
        pu.PUVersion = dll_PUVersion.Text;
        return pu;
    }
}